package com.terry.test2.new2.impl;

import com.terry.test2.Result;
import com.terry.test2.dp.Account;
import com.terry.test2.dp.ExchangeRate;
import com.terry.test2.dp.Money;
import com.terry.test2.new2.AccountTransferService;

import javax.xml.bind.ValidationException;

/**
 * @author 小八
 * @date 2023年02月02日10:49
 */
public class AccountTransferServiceImpl implements AccountTransferService {

    @Override
    public Result<Boolean> transfer(Account sourceAccount, Account targetAccount, Money money, ExchangeRate exchangeRate) throws ValidationException {
        Money sourceMoney = exchangeRate.exchange(money);
        sourceAccount.withdraw(sourceMoney);
        targetAccount.deposit(sourceMoney);
        return Result.success(true);
    }

}
